/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.saga.lib.asyncserver;

import java.nio.channels.AsynchronousByteChannel;
/**
 * 
 * Connection State objects should be build assuming they are 
 * going to be cached and reused.  
 *
 * @author summers
 */
public interface ConnectionState {
    /**
     * The method is which calls run is responsible for noticing a state change and running {@link #cleanup() clenup}.
     * 
     * @return the next state to implement run on.  Can be the same instance, a new instance, or null.  Null state means disconnect
     * 
     */
    ConnectionState run();
    
    /**
     * This sets the channel being used by this instance
     * 
     * @param channel 
     */
    void setChannel(AsynchronousByteChannel channel);
    
    /**
     * 
     * This should be thought of as a destructor.
     * This should set the channel to null.
     */
    void cleanup();
    
}
